package com.benshou.bsoa.controller.yida;

import com.benshou.bsoa.common.dto.ResponseVo;
import com.benshou.bsoa.dto.yida.req.YiDaReq;
import com.benshou.bsoa.dto.yida.req.YiDaSearchReq;
import com.benshou.bsoa.service.yida.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/yida")
public class YiDaController {

    @Autowired
    private PostYiDaService yiDaService;

    @Autowired
    private GetYiDaService getYiDaService;

    @Autowired
    private UpdateYiDaService updateYiDaService;

    @Autowired
    private GetComponentsDefineService getComponentsDefineService;

    @Autowired
    private SearchYiDaService searchYiDaService;

    @Autowired
    private ProjectProgressService projectProgressService;

    @Autowired
    private TaskDocumentSummaryService taskDocumentSummaryService;

    /**
     * 新增表单实例
     * @param yiDaReq 前端传递的参数
     * @return 处理结果
     */
    @PostMapping("/createFormInstance")
    public ResponseVo createFormInstance(@RequestBody YiDaReq yiDaReq) throws Exception {
        // 调用服务层处理逻辑
        return ResponseVo.success(yiDaService.saveFormData(yiDaReq));
    }

    /**
     * 查询表单实例数据
     * @param yiDaReq 前端传递的参数
     * @return 查询结果
     */
    @PostMapping("/queryFormInstance")
    public ResponseVo queryFormInstance(@RequestBody YiDaReq yiDaReq) throws Exception {
        // 调用服务层处理逻辑
        return ResponseVo.success(getYiDaService.queryListFormData(yiDaReq));
    }

    /**
     * 查询单条表单实例数据
     * @param yiDaReq 前端传递的参数
     * @return 处理结果
     */
    @PostMapping("/querySingleFormInstance")
    public ResponseVo querySingleFormInstance(@RequestBody YiDaReq yiDaReq) throws Exception {
        // 调用服务层处理逻辑
        return ResponseVo.success(getYiDaService.querySingleFormData(yiDaReq));
    }
    /**
     * 查询表单组件定义列表
     * @param yiDaReq 前端传递的参数
     * @return 处理结果
     */
    @PostMapping("/queryFormComponentDefinitionList")
    public ResponseVo queryFormComponentDefinitionList(@RequestBody YiDaReq yiDaReq) throws Exception {
        // 调用服务层处理逻辑
        return ResponseVo.success(getComponentsDefineService.getFormComponentDefinitionListRequest(yiDaReq));
    }

    /**
     * 更新表单实例数据
     * @param yiDaReq 前端传递的参数
     * @return 处理结果
     */
    @PostMapping("/updateFormInstance")
    public ResponseVo updateFormInstance(@RequestBody YiDaReq yiDaReq) throws Exception {
        // 调用服务层处理逻辑
        return ResponseVo.success(updateYiDaService.updateFormData(yiDaReq));
    }

    /**
     * 搜索表单实例数据
     * @param yiDaReq 前端传递的参数
     * @return 处理结果
     */
    @PostMapping("/searchFormInstance")
    public ResponseVo searchFormInstance(@RequestBody YiDaSearchReq yiDaReq) throws Exception {
        // 调用服务层处理逻辑
        return ResponseVo.success(searchYiDaService.searchFormData(yiDaReq));
    }

    /**
     * 更新项目进度文档汇总
     * @param formInstanceId 项目进度实例ID
     * @return 处理结果
     */
    @PostMapping("/updateProjectProgressDocumentSummary/{formInstanceId}")
    public ResponseVo updateProjectProgressDocumentSummary(@PathVariable String formInstanceId) throws Exception {
        // 调用服务层处理逻辑
        boolean result = projectProgressService.updateProgressDocument(formInstanceId);
        return ResponseVo.success(result);
    }


    /**
     * 更新任务文档汇总
     * @param formInstanceId 任务表单实例ID
     */
    @PostMapping("/updateTaskDocumentSummary/{formInstanceId}")
    public ResponseVo updateTaskDocumentSummary(@PathVariable String formInstanceId) throws Exception {
        // 调用服务层处理逻辑
        boolean result = taskDocumentSummaryService.updateTaskDocumentSummary(formInstanceId);
        return ResponseVo.success(result);
    }
}